﻿@page "/任务列表/{Parameter}"
@using System.Diagnostics.CodeAnalysis
@inject SqlSugarScope _SqlSugarScope
@inject ToastService ToastService
@inject AuthenticationStateProvider authenticationStateProvider
@rendermode InteractiveServer
@inject NavigationManager NavigationManager


<BootstrapBlazorRoot>
<h3>任务列表</h3>

<Table TItem="Bus_项目任务明细" Items="@Items" @ref="TableRows" IsStriped="true" IsBordered="true"
           ShowToolbar="false" ShowDefaultButtons="false"
           ShowExtendButtons="true" ShowExtendEditButton="false" ShowExtendDeleteButton="false" ExtendButtonColumnWidth="240">
    <TableColumns>
        <TableColumn @bind-Field="@context.行号" />
        <TableColumn @bind-Field="@context.结算类型" />
        <TableColumn @bind-Field="@context.结算开始日期" />
        <TableColumn @bind-Field="@context.结算结束日期" />
        <TableColumn @bind-Field="@context.名称" />
        <TableColumn @bind-Field="@context.规格" />
        <TableColumn @bind-Field="@context.数量" />
        <TableColumn @bind-Field="@context.单位" />
        <TableColumn @bind-Field="@context.结算金额" />
        <TableColumn @bind-Field="@context.含税单价"/>
    </TableColumns>
    <RowButtonTemplate>
        <TableCellButton Icon="fa-solid fa-pen" Text="派单" OnClick="@(() => OnRowButtonClick(context, "派单"))" />
    </RowButtonTemplate>
</Table>
</BootstrapBlazorRoot>
@code {
    [Parameter]
    public string Parameter { get; set; }

    [NotNull]
    private List<Bus_项目任务明细>? Items { get; set; }

    [NotNull]
    private Table<Bus_项目任务明细>? TableRows { get; set; }

    //初始化方法
    protected override async Task OnInitializedAsync()
    {
        显示已有的任务();
    }

    private void 显示已有的任务()
    {
       Guid.TryParse(Parameter,out Guid guid);
        Items = _SqlSugarScope.Queryable<Bus_项目任务明细>()
            .Where(it => it.guid == guid && (it.已失效 == false || it.已失效 == null))
            .OrderBy(it => it.CreateDate, OrderByType.Desc)
            .ToList();
    }

    private async Task OnRowButtonClick(Bus_项目任务明细 item, string text)
    {
        Guid? guid = item.bguid;
        NavigationManager.NavigateTo($"/派单/{guid}");
    }
}
